package com.xudu.controller.impl;

import com.xudu.common.Result;
import com.xudu.exception.AppException;
import com.xudu.exception.AppExceptionCodeMsg;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * ClassName: TestExceptionControllerImpl
 * Description:
 *
 * @Author xudu
 * @Create 2024/4/18
 */
@RestController
public class TestExceptionControllerImpl {

    @GetMapping("testexception")
    public Result test(String str){

        if("ok".equals(str)){
            return Result.success("succ");
        }
        if("err".equals(str)){
            //抛业务相关的异常
            throw new AppException(AppExceptionCodeMsg.USERNAME_NOT_EXISTS);
        }

        if("errpwd".equals(str)){
            throw new AppException(AppExceptionCodeMsg.INVALID_PASSWORD);
        }
        if("0".equals(str)){
            int i=1/0;
        }


        if("token".equals(str)){
            throw new AppException(AppExceptionCodeMsg.TOKEN_EXPIRATION);
        }

        return Result.success();
    }

    @GetMapping("list")
    public Result list(){
        List<String> list = Arrays.asList("zhangsan","lisi","wangwu");

        return Result.success(list);
    }
}
